<script>
  import wxSdk from 'utils/wx'

  export default {
    async beforeCreate() {
      console.log('app created')
      App.systemInfo = wx.getSystemInfoSync();
      console.log(App.systemInfo)
      wxSdk.init();
      App.fetchLogin = async function () {
        wx.showLoading({ title: '加载中', mask: true });
        const { code } = await wx.login();
        //1、res.code登录
        const { openId } = await wx.request({
          url: `https://ap.granwin.com/fr/login/wxCode?wxCode=${code}`,
        })
        App.openId = openId;
        wx.hideLoading()
        const loginResult = await wx.request({
          url: '/app/users',
          method: 'POST',
          data: {
            phone_id: openId,
          },
        })
        console.info(loginResult)
        App.userInfo = loginResult;
      }.bind(this)
      wx.loadFontFace({
        family: 'PingFang',
        source: 'url("https://ap.granwin.com/images/ph.ttf")',
      })
    }
  }
</script>

<style lang="scss">
  @import "./styles/base";

</style>
